package home;

import games.SimpleMatch;

import java.util.List;

import operations.HibernateManager;

import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import teams.Team;

public class SimpleMatchHome {

    public List<SimpleMatch> getMatches(final Team team1, final Team team2) {
        Session session = HibernateManager.instance().getSession();
        Criteria criteria = session.createCriteria(SimpleMatch.class);

        Criterion criterio1 = Restrictions.or(Restrictions.eq("team1", team1), Restrictions.eq("team2", team1));
        Criterion criterio2 = Restrictions.or(Restrictions.eq("team1", team2), Restrictions.eq("team2", team2));

        criteria.add(Restrictions.and(criterio1, criterio2));
        return criteria.list();

    }
}